package com.onejson.ojmall.controller;


import com.onejson.ojmall.common.domain.PageResult;
import com.onejson.ojmall.common.apiencrypt.domain.ValidateList;
import com.onejson.ojmall.common.domain.ResponseDTO;
import com.onejson.ojmall.model.form.SRoleBatchForm;
import com.onejson.ojmall.model.form.SRoleForm;
import com.onejson.ojmall.model.form.SRoleQueryForm;
import com.onejson.ojmall.model.vo.SRoleVO;
import com.onejson.ojmall.service.SRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 角色表控制器
 *
 * @author wxx
 */
@Slf4j
@RestController
@Tag(name = "角色表")
//@OperateLog
public class SRoleController {


    //【角色表】Service层

    @Resource
    private SRoleService sRoleService;


    @Operation(summary = "【角色表】 - 查询")
    @PostMapping("/zichan/sRole/queryPage")
    public ResponseDTO<PageResult<SRoleVO>> querySRole(@RequestBody @Valid SRoleQueryForm queryForm) {
        return ResponseDTO.ok(sRoleService.getList(queryForm));
    }

    @Operation(summary = " 【角色表】 - 详情")
    @GetMapping("/zichan/sRole//{detailId}")
    public ResponseDTO<SRoleVO> getInfo(@PathVariable("detailId") String detailId) {
        return ResponseDTO.ok(sRoleService.queryById(detailId));
    }

    @Operation(summary = " 【角色表】 - 添加")
    @PostMapping("/zichan/sRole/add")
    public ResponseDTO<String> addSRole(@RequestBody @Valid SRoleForm addForm) {
        return sRoleService.addSRole(addForm);
    }

    @Operation(summary = "【角色表】 - 更新")
    @PostMapping("/zichan/sRole/update")
    public ResponseDTO<String> updateSRole(@RequestBody @Valid SRoleForm updateForm) {
        return sRoleService.updateSRole(updateForm);
    }

    @Operation(summary = "【角色表】 - 批量更新")
    @PostMapping("/zichan/sRole/batchUpdate")
    public ResponseDTO<String> batchUpdateSRole(@RequestBody @Valid SRoleBatchForm sRoleBatchForm) {
        return sRoleService.batchUpdateSRole(sRoleBatchForm);
    }

    @Operation(summary = "【角色表】 - 批量删除")
    @PostMapping("/zichan/sRole/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<String> idList) {
        return sRoleService.batchDelete(idList);
    }

    @Operation(summary = "【角色表】 - 单个删除")
    @GetMapping("/zichan/SRole/delete/{id}")
    public ResponseDTO<String> batchDelete(@PathVariable String id) {
        return sRoleService.delete(id);
    }

}

